//
//  Persion.m
//  Runtime
//
//  Created by lvfeijun on 2021/10/27.
//

#import "Persion.h"
#import <objc/runtime.h>

@implementation Persion

- (void)eat{
    NSLog(@"eat");
}

-(void)eat2{
    NSLog(@"eat2");
    
}
+(void)eat2{
    NSLog(@"eat2");
    
}

+ (BOOL)resolveInstanceMethod:(SEL)sel{
    NSLog(@" %@ 来了",NSStringFromSelector(sel));

    if (sel == @selector(eat1)) {
        NSLog(@"%@ 来了resolveInstanceMethod",NSStringFromSelector(sel));

        IMP imp = class_getMethodImplementation(self, @selector(eat2));
        Method sayMMethod = class_getInstanceMethod(self, @selector(eat2));
        const char *type  = method_getTypeEncoding(sayMMethod);
        return class_addMethod(self, sel, imp, type);
    }
    return [super resolveInstanceMethod:sel];
   
}
+ (BOOL)resolveClassMethod:(SEL)sel{
    NSLog(@"%@ 来了",NSStringFromSelector(sel));

    if (sel == @selector(eat1)) {
        NSLog(@"%@ 来了resolveClassMethod",NSStringFromSelector(sel));

        IMP imp = class_getMethodImplementation(self, @selector(eat2));
        Method sayMMethod = class_getInstanceMethod(self, @selector(eat2));
        const char *type  = method_getTypeEncoding(sayMMethod);
//        return class_addMethod(self.class, @selector(eat2), imp, type);
        return class_addMethod(self.class, sel, imp, type);
    }
    return [super resolveClassMethod:sel];
}


@end
